package dicebot.tools.dice;

public class Negation extends DiceExpression {
    
    public DiceExpression var;

    @Override
    public DiceExpression simplify() throws Exception {
        if (var instanceof Number) {
            return new Number(-((Number) var).value);
        } else {
            var = var.simplify();
            return this;
        }
    }

    public Negation (DiceExpression var) {
        this.var = var;
    }

    @Override
    public String toString() {
        String s = var.toString();
        if (var instanceof Add || var instanceof LongAdd || var instanceof Negation) {
            s = "(" + s + ")";
        }
        return "-" + s;
    }

    @Override
    public String toStringWithSign() {
        return toString();
    }
}
